package com.mengdie.shuidi.ui.activity;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.flyco.tablayout.SlidingTabLayout;
import com.mengdie.shuidi.R;
import com.mengdie.shuidi.ui.fragment.LineFragment;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by apple on 16/10/14.
 */

public class ProvinceActivity extends BaseActivity {

    @Bind(R.id.rl_generic_back)
    RelativeLayout mRlGenericBack;
    @Bind(R.id.tv_generic_title)
    TextView mTvGenericTitle;
    @Bind(R.id.tl_fqa_top)
    SlidingTabLayout mTlFqaTop;
    @Bind(R.id.vp_fqa_bottom)
    ViewPager mVpFqaBottom;

    private String[] mTitles;
    private ArrayList<Fragment> mFragments = new ArrayList<>();
    private MyPagerAdapter mAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_line_province);
        ButterKnife.bind(this);
        initListener();
    }

    private void initListener() {
        mRlGenericBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        mTvGenericTitle.setText("线路选择");
        mFragments.add(LineFragment.newInstance("false", "2"));
        mFragments.add(LineFragment.newInstance("true", "1"));
        mTitles = getResources().getStringArray(R.array.line_select_one);
        mAdapter = new MyPagerAdapter(getSupportFragmentManager());
        mVpFqaBottom.setAdapter(mAdapter);
        mTlFqaTop.setViewPager(mVpFqaBottom);
        mVpFqaBottom.setCurrentItem(0);

    }


    private class MyPagerAdapter extends FragmentPagerAdapter {
        public MyPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public int getCount() {
            return mFragments.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mTitles[position];
        }

        @Override
        public Fragment getItem(int position) {
            return mFragments.get(position);
        }
    }
}
